<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>分类新增</title>
    <link rel="stylesheet" href="../../component/pear/css/pear.css" />
    <style>
        .expand.pear-btn:hover {
            color: currentColor;
            background: none;
        }

        .expand.pear-btn {
            border: 1px solid rgba(255, 255, 255, 0)
        }
    </style>
</head>

<body class="pear-container">
    <form class="layui-form" action="" onsubmit="return false">
        <div class="layui-form-item">
            <label class="layui-form-label">上级分类</label>
            <div class="layui-input-inline">
                <input type="text" id ='sjflmc' readonly  required lay-verify="required" autocomplete="off"
                    class="layui-input" >
                    <input type="text" name="pid" id="pid" hidden="hidden" style="display: none" required lay-verify="required" placeholder="请输入输入框内容" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">分类名称</label>
            <div class="layui-input-inline">
                <input type="text" name="name" required lay-verify="required" placeholder="请输入输入框内容" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-inline">
                <input type="text" name="num" required lay-verify="required" placeholder="请输入输入框内容"
                    autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button  class="pear-btn pear-btn-primary pear-btn-md"  lay-submit lay-filter="formDemo">保存</button>
                <button type="reset" class="pear-btn pear-btn-primary pear-btn-md" >重置</button>
            </div>
        </div>
    </form>
</body>

</html>
<script src="../../component/layui/layui.js"></script>
<script src="../../component/pear/pear.js"></script>
<script>

    layui.use(['table', 'form', 'upload', 'layer', 'laydate', 'jquery', 'util', 'drawer', 'dropdown','popup'], function () {
        var table = layui.table,
            laydate = layui.laydate,
            form = layui.form,
            $ = layui.$,
            layer = layui.layer,
            upload = layui.upload
            , util = layui.util;
        let drawer = layui.drawer;
        let dropdown = layui.dropdown;
        var popup = layui.popup;

        //layer.msg(getUrlParam("name"));
        //alert(getUrlParam('name'));
        $("#sjflmc").val(getUrlParam("name"));
        $("#pid").val(getUrlParam("id"));
        form.on('submit(formDemo)', function (data) {
            //layer.msg(JSON.stringify(data.field));
            $.ajax({
                type: "post",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                url: 'http://localhost:5161/api/ClassFy/ClassFyAdd',
                data: JSON.stringify(data.field),
                headers: {
                    "Authorization": sessionStorage.getItem("token")
                },
                success: function (response) {
                    //alert(response.result);
                    if (response.result) {
                        parent.layer.msg("新增成功!", {time: 1000,icon: 1}, function () {
                            //重新加载父页面
                            parent.location.reload();

                            });
                    } else {
                        popup.failure("新增失败:" + data.msg);
                    }
                    
                }
            });
            return false;
        });

    });
</script>